﻿using EnvDTE80;
using TddGenerator.Core.Domain;
using TddGenerator.Core.Services;
using TddGenerator.Core.Services.Impl;
using TddGenerator.Ui;

namespace TddGenerator.Addin.Services.Impl
{

    public class PresenterFactory : IPresenterFactory
    {
        public InterfaceUnderTestSelectorPresenter GetPresenter(DTE2 dte, IInterfaceUnderTestSelectorView view)
        {
            return this.GetPresenter(dte, view, new TemplateSetRepository(new FileSystemService()));
        }

        public InterfaceUnderTestSelectorPresenter GetPresenter(DTE2 dte, IInterfaceUnderTestSelectorView view, ITemplateSetRepository templateRepository)
        {
            var repository = new ProjectRepository(dte);

            var vsIdeService = new VsIdeService(dte, new FileSystemService());

            IDefaultSettingsRepository defaultSettingsRepository = new DefaultSettingsRepository(new FileLocator(vsIdeService),
                                                                                                 new XmlFileSerializer
                                                                                                     <DefaultSettings>(),
                                                                                                 new FileSystemService());

            
            var tokenFactory = new TokenFactory(vsIdeService);
            var generator = new ClassGenerator(templateRepository,
                                               vsIdeService, null, tokenFactory,
                                               new ConfigurationRepository());
            var presenter = new InterfaceUnderTestSelectorPresenter(repository, view,
                                                                    generator,
                                                                    defaultSettingsRepository);
            return presenter;
        }
    }
}